home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / vcafe / samples.bin / ThreadX.java < prev    next >
Encoding:
Java Source  |  1996-09-04  |  3.4 KB  |  115 lines

  1. /*
  2.     This class is a basic extension of the Applet class.  It would generally be
  3.     used as the main class with a Java browser or the AppletViewer.  But, an instance
  4.     can be added to a subclass of Container.  To use this applet with a browser or
  5.     the AppletViewer, create an html file with the following code:
  6.  
  7.     <HTML>
  8.     <HEAD>
  9.     <TITLE>ThreadX window</TITLE>
  10.     </HEAD>
  11.     <BODY>
  12.  
  13.     <APPLET CODE="ThreadX.class" WIDTH=380 HEIGHT=180></APPLET>
  14.  
  15.     </BODY>
  16.  
  17.     </HTML>
  18.  
  19.     You can add controls to ThreadX with Cafe Studio, but not menus.  (Menus
  20.     can only be added to subclasses of Frame.)
  21.  */
  22.  
  23. import java.awt.*;
  24.  
  25. public class ThreadX extends java.applet.Applet {
  26.  
  27.     AnimationPanel panelOne, panelTwo, panelThree;
  28.  
  29.     public void init() {
  30.  
  31.         //{{INIT_CONTROLS
  32.         setLayout(new BorderLayout(0,0));
  33.         addNotify();
  34.         resize(500,280);
  35.         animationArea = new java.awt.Panel();
  36.         animationArea.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
  37.         animationArea.resize(animationArea.preferredSize());
  38.         animationArea.move(28, 6);
  39.         add("Center", animationArea);
  40.         mainButtonPanel = new java.awt.Panel();
  41.         mainButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
  42.         mainButtonPanel.resize(mainButtonPanel.preferredSize());
  43.         mainButtonPanel.move(28, 172);
  44.         add("South", mainButtonPanel);
  45.         aStartButton = new java.awt.Button("All Start");
  46.         aStartButton.resize(aStartButton.preferredSize());
  47.         aStartButton.move(76, 200);
  48.         mainButtonPanel.add(aStartButton);
  49.         aStopButton = new java.awt.Button("All Stop");
  50.         aStopButton.resize(aStopButton.preferredSize());
  51.         aStopButton.move(198, 200);
  52.         mainButtonPanel.add(aStopButton);
  53.         resetButton = new java.awt.Button("Reset");
  54.         resetButton.resize(resetButton.preferredSize());
  55.         resetButton.move(318, 200);
  56.         mainButtonPanel.add(resetButton);
  57.         //}}
  58.  
  59.         animationArea.setLayout(new GridLayout(1,3));
  60.  
  61.         //Add three new AnimationPanels with the specified color and delay
  62.         //to the animationArea.
  63.         animationArea.add(panelOne = new AnimationPanel(Color.red, 75));
  64.         animationArea.add(panelTwo = new AnimationPanel(Color.white, 100));
  65.         animationArea.add(panelThree = new AnimationPanel(Color.blue, 125));
  66.  
  67.         super.init();
  68.     }
  69.  
  70.     public boolean handleEvent(Event event) {
  71.         if (event.id == Event.ACTION_EVENT && event.target == resetButton) {
  72.                 Reset();
  73.                 return true;
  74.         }
  75.         else
  76.         if (event.id == Event.ACTION_EVENT && event.target == aStopButton) {
  77.                 AllStop();
  78.                 return true;
  79.         }
  80.         else
  81.         if (event.id == Event.ACTION_EVENT && event.target == aStartButton) {
  82.                 AllStart();
  83.                 return true;
  84.         }
  85.  
  86.         return super.handleEvent(event);
  87.     }
  88.  
  89.     //{{DECLARE_CONTROLS
  90.     java.awt.Panel animationArea;
  91.     java.awt.Panel mainButtonPanel;
  92.     java.awt.Button aStartButton;
  93.     java.awt.Button aStopButton;
  94.     java.awt.Button resetButton;
  95.     //}}
  96.  
  97.     public void AllStart() {
  98.         panelOne.StartAnimation();
  99.         panelTwo.StartAnimation();
  100.         panelThree.StartAnimation();
  101.     }
  102.     public void AllStop() {
  103.         panelOne.StopAnimation();
  104.         panelTwo.StopAnimation();
  105.         panelThree.StopAnimation();
  106.     }
  107.     public void Reset() {
  108.         panelOne.ResetAnimation();
  109.         panelTwo.ResetAnimation();
  110.         panelThree.ResetAnimation();
  111.     }
  112. }
  113.  
  114.  
  115.